<template>
  <div class="groupStatistics">
    <ul class="Statistics">
      <li>
        <div class="li-top">
          <div class="number-big">
            <div class="number-code">客户总数</div>
            <div class="number-content">4</div>
          </div>
          <img src="@/assets/images/home/home1.png"/>
        </div>
        <div class="li-bottom">
          <div class="bottom-top">
            <div class="code">昨日总数：</div>
            <div class="content">4</div>
            <el-tooltip class="item" effect="dark" placement="top-start">
              <div slot="content" class="tooltipContent">
                <p> 昨日客户总数：</p>
                <p>截止至昨日，所有企微号添加的客户数量总和，不去重；</p>
                <p>日、周、月：</p>
                <p>分别计算昨日数据相比1天、7天、30天前的变化情况；</p>
              </div>
              <i class="el-icon-question"></i>
            </el-tooltip>
          </div>
          <div class="bottom-di">
            <!--          有可能是上升，有可能是下降要做判断-->
            <div class="li-item">日<span><img src="@/assets/images/xia.png"/>0.0%</span></div>
            <div class="li-item">周<span><img src="@/assets/images/shang.png"/>0.0%</span></div>
            <div class="li-item">月<span><img src="@/assets/images/xia.png"/>0.0%</span></div>
          </div>
        </div>
      </li>
      <li>
        <div class="li-top">
          <div class="number-big">
            <div class="number-code">今日新增客户</div>
            <div class="number-content">4</div>
          </div>
          <img src="@/assets/images/home/home2.png"/>
        </div>
        <div class="li-bottom">
          <div class="bottom-top">
            <div class="code">昨日新增：
            </div>
            <div class="content">4
            </div>
            <el-tooltip class="item" effect="dark" placement="top-start">
              <div slot="content" class="tooltipContent">
                <p>昨日新增客户：</p>
                <p>昨日所有企微号添加的客户数量总和，同个客户多个成员添加，不去重；</p>
                <p>日、周、月：</p>
                <p>分别计算昨日数据相比1天、7天、30天前的变化情况；</p>
              </div>
              <i class="el-icon-question"></i>
            </el-tooltip>
          </div>
          <div class="bottom-di">
            <!--          有可能是上升，有可能是下降要做判断-->
            <div class="li-item">日<span><img src="@/assets/images/xia.png"/>0.0%</span></div>
            <div class="li-item">周<span><img src="@/assets/images/shang.png"/>0.0%</span></div>
            <div class="li-item">月<span><img src="@/assets/images/xia.png"/>0.0%</span></div>
          </div>
        </div>
      </li>
      <li>
        <div class="li-top">
          <div class="number-big">
            <div class="number-code">今日流失客户</div>
            <div class="number-content">4</div>
          </div>
          <img src="@/assets/images/home/home3.png"/>
        </div>
        <div class="li-bottom">
          <div class="bottom-top">
            <div class="code">昨日新增：</div>
            <div class="content">4</div>
            <el-tooltip class="item" effect="dark" placement="top-start">
              <div slot="content" class="tooltipContent">
                <p> 昨日流失客户：</p>
                <p>昨日所有企微号流失的客户数量总和，同个客户多个成员添加，不去重；</p>
                <p>日、周、月：</p>
                <p>分别计算昨日数据相比1天、7天、30天前的变化情况；</p>
              </div>
              <i class="el-icon-question"></i>
            </el-tooltip>
          </div>
          <div class="bottom-di">
            <!--          有可能是上升，有可能是下降要做判断-->
            <div class="li-item">日<span><img src="@/assets/images/xia.png"/>0.0%</span></div>
            <div class="li-item">周<span><img src="@/assets/images/shang.png"/>0.0%</span></div>
            <div class="li-item">月<span><img src="@/assets/images/xia.png"/>0.0%</span></div>
          </div>
        </div>
      </li>
    </ul>
    <div class="chart-big">
      <div class="chart-li">
        <div class="title"><div>客户来源</div> <span>详情</span></div>
        <indexPie  :id="`typeContent`" :dataList="dataList"></indexPie>
      </div>
      <div class="chart-li">
        <div class="title"><div>性别占比</div> <span>详情</span></div>
        <indexPie  :id="`sexContent`" :dataList="sexList"></indexPie>
      </div>
      <div class="chart-li">
        <div class="title"><div>标签下的客户</div>
          <el-select v-model="value" placeholder="请选择" size="mini" style="margin-top: -5px; width: 130px">
          <el-option
            v-for="item in typeList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select></div>
        <div class="homeLabelList">
          <div class="item-li">
            <div class="sort red">1</div>
            <div class="content">核心</div>
             <div class="num">（3）</div>
          </div>
          <div class="item-li">
            <div class="sort orange">2</div>
            <div class="content">重要</div>
            <div class="num">（5）</div>
          </div>
          <div class="item-li">
            <div class="sort blue">3</div>
            <div class="content">一般</div>
            <div class="num">（5）</div>
          </div>
        </div>
      </div>
    </div>
<!--    折线图的图层-->
    <div class="time-big">
      <ul class="timeType">
        <li :class="selectedRange=='last7Days'?`active`:``" @click="getTime('last7Days')">近7天</li>
        <li :class="selectedRange=='last15Days'?`active`:``" @click="getTime('last15Days')">近15天</li>
        <li :class="selectedRange=='last30Days'?`active`:``" @click="getTime('last30Days')">近30天</li>
      </ul>
      <el-date-picker
        size="small"
        v-model="timeRange"
        style="width: 240px"
        value-format="yyyy-MM-dd"
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      ></el-date-picker>
    </div>
    <div class="line-big">
      <div class="line-left">
        <div class="title"><div>客户总数</div></div>
        <lineEchart :id="`trendAnalysisContent`"  :lineXDataList="lineXDataList" :lineYDataList="lineYDataList"></lineEchart>
      </div>
      <div class="line-right">
        <div class="title"><div>新增和流失</div></div>
        <lineEchart :id="`addContent`"  :lineXDataList="lineXDataList" :lineYDataList="addOrMissUserList"></lineEchart>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "groupStatistics",
  components:{
    'indexPie':()=> import('./indexPie.vue'),
    'lineEchart': () => import('./lineEchart.vue'),//导出弹窗
  },
  computed: {
    dateRange() {
      const now = new Date();
      switch (this.selectedRange) {
        case 'yesterday':
          return [
            new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1),
            new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1),
          ];
        case 'today':
          return [
            now,
            new Date(now.getFullYear(), now.getMonth(), now.getDate()),
          ];
        case 'last7Days':
          return [
            new Date(now.getTime() - (6 * 24 * 60 * 60 * 1000)),
            now,
          ];
        case 'last15Days':
          return [
            new Date(now.getTime() - (14 * 24 * 60 * 60 * 1000)),
            now,
          ];
        case 'last30Days':
          return [
            new Date(now.getTime() - (29 * 24 * 60 * 60 * 1000)),
            now,
          ];
        default:
          return [];
      }
    },
  },
  data(){
    return{
      value:'',//选择公司
      typeList:[
        {value:1, label:'锐行',},
        {value:2, label:'志星',}
      ],
      dataList:[
        {value:1000,name:'扫一扫',},
        {value:1200,name:'微信好友',},
        {value:1200,name:'新增群聊数',},
        {value:600,name:'群聊总数',},
        {value:800,name:'群成员总数',},
      ],
      sexList:[
        {value:1000,name:'男',},
        {value:1200,name:'女',},
      ],
      selectedRange: 'today',
      timeRange:[],//时间范围
      lineXDataList:['2023-01', '2023-02', '2023-03', '2023-04'],
      lineYDataList:[{
        name: '客户总数',
        type: 'line',
        stack: 'Total',
        data: [120, 132, 101, 134]
      }],
      addOrMissUserList:[{
        name: '新增客户数',
        type: 'line',
        stack: 'Total',
        data: [120, 132, 101, 134]
      },
        {
          name: '新增流失客户数',
          type: 'line',
          stack: 'Total',
          data: [50, 32, 80, 10]
        }
      ],
    }
  },
  created() {
    this.getTime('last30Days');//近30天
  },
  methods:{
    getTime(type) {
      this.selectedRange = type;
      setTimeout(() => {
        console.log('时间范围', this.dateRange);
        this.timeRange = [];
        this.timeRange = [this.fiterTime(this.dateRange[0]), this.fiterTime(this.dateRange[1])];
        console.log('转化时间', this.timeRange);
      }, 0)
    },
    fiterTime(value) {
      if (!value) return '';
      const date = new Date(value);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
  },
}
</script>
<style scoped lang="scss">
.Statistics {
  display: flex;
  margin: 0px -10px;
  margin-top: 15px;

  li {
    list-style: none;
    flex: 1;
    display: flex;
    padding: 0 16px;
    margin: 0 8px;
    border-radius: 4px;
    flex-direction: column;
    background-color: #f7f7f7;

    .li-top {
      display: flex;
      height: 80px;
      background-repeat: no-repeat;
      background-size: cover;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #f0f0f0;

      img {
        width: 40px;
        height: 40px;
      }

      .number-content {
        color: rgba(0, 0, 0, 0.85);
        font-weight: bold;
        font-size: 24px;
        font-family: DINAlternate-Bold, DINAlternate;
      }
    }

    .li-bottom {
      .bottom-top {
        display: flex;
        align-items: center;
        color: rgba(0, 0, 0, .85);
        padding: 12px 8px 8px 0;
        position: relative;

        .content {
          color: rgb(251, 88, 78);
        }
      }
    }
  }
}
.tooltipContent {
  max-width: 300px;
  p{
    line-height: 20px;
    margin:5px 0px;
    padding: 0px;
  }
}
.bottom-di {
  display: flex;
  color: rgba(0, 0, 0, .85);
  padding: 0 0 12px;
  .li-item {
    margin-right: 20px;
    font-size: 12px;
    span {
      margin-left: 5px;
      img {
        margin-right: 3px;
      }
    }
  }
}
.chart-big {
display: flex;
  border: 1px solid #f5f5f5;
  margin: 16px 0px;
  .chart-li {
    display: flex;
    width: 33.33333%;
    height: 220px;
    border-right: 1px solid #f5f5f5;
    padding: 16px;
    flex-direction: column;
  }
}
.title {
  font-size: 14px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  width: 100%;

  span {
    color: #2d8cf0;
    font-weight: 400;
  }
}
.homeLabelList {
  margin-top: 16px;
  .item-li {
    display: flex;
    margin-bottom: 8px;
    align-items: center;
    .sort {
      display: inline-block;
      width: 20px;
      height: 20px;
      color: #fff;
      text-align: center;
      line-height: 20px;
      font-size: 12px;
      background-color: #ddd;
      margin-right: 12px;
      border-radius: 2px;
      &.red {
        background-color: #fb584e;
      }
      &.orange {
        background-color: #ff8243;
      }
      &.blue {
        background-color: #576b95;
      }
    }
  }
}
.time-big {
  display: flex;
  align-items: center;
}
.timeType {
  display: flex;
  align-items: center;
  margin-right: 10px;

  li {
    border: 1px solid #eee;
    height: 32px;
    margin: 0;
    padding: 0 15px;
    list-style: none;
    cursor: pointer;
    align-items: center;
    display: flex;
     &:first-child{
       border-radius: 4px 0px 0px 4px;
     }
    &:last-child{
      border-radius: 0px 4px 4px 0px;
    }
    &.active {
      border-color: #2d8cf0;
      color: #2d8cf0;
    }
  }
}
.line-big {
  display: flex;
  .line-left {
    flex: 1;
    padding: 15px 10px 0px 10px;
  }
  .line-right {
    flex: 1;
    padding: 10px;
    padding: 15px 10px 0px 10px;
  }
}
</style>
